﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master/HomeSubMaster.Master" AutoEventWireup="true"
    CodeBehind="CreateOrder.aspx.cs" Inherits="CSP.Web.MyHome.ConsumeOrder.CreateOrder" %>

<asp:Content ID="CSPHead" ContentPlaceHolderID="CSPHead" runat="server">
    <meta charset="utf-8">
    <title>创建订单--信然贷网</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
</asp:Content>
<asp:Content ID="CSPStyleAndScript" ContentPlaceHolderID="CSPStyleAndScript" runat="server">
    <link href="/Styles/theme/base/main/book.css" rel="stylesheet">
    <script type="text/javascript" src="/Scripts/Validate/validate.js"></script>
    <script type="text/javascript" src="/Scripts/UI/Expand/dialog.js"></script>
    <script type="text/javascript">

    var online = new Array();
    
    var CSPContact={
        isFinded:false,
        contactWays:<%=ContactWayJson %>,
        Init:function (){
            var that=this;
            var qqFilePath='http://'+'webpresence.qq.com/getonline?'+encodeURI('Type=1&');
            var taobaoFilePath='http://'+'amos.alicdn.com/muliuserstatus.aw?beginnum=0&site=cntaobao&charset=utf-8&callback=<%=this.ClientID %>.SetContact&uids=';
            var taobaoi=0;
            $.each(this.contactWays,function(idex,item){
                /*1代表是QQ*/
                if(item.Type==1 ){
                    qqFilePath+=item.Address+":";
                }
                /*0代表淘宝*/
                if(item.Type==0){
                    if(taobaoi==0){
                        taobaoFilePath+=encodeURI(item.Address);
                    }else{
                        taobaoFilePath+=";"+encodeURI(item.Address);
                    }
                    
                    taobaoi++;
                }
            });
            //$.includeFile([qqFilePath]);
            $.ajax({
              type:"get",
              url: qqFilePath,
              cache:false ,
              dataType: "script",
              async:false,
              error:function(XMLHttpRequest, textStatus, errorThrown){
                var bbb="";
              },
              success:function (data, textStatus, jqXHR){
                that.SetContact();
              }
            });
            if(this.isFinded){
                return;
            }
            $.ajax({
              type:"get",
              url: taobaoFilePath,
              cache:false ,
              dataType: "script",
              async:false,
              error:function(XMLHttpRequest, textStatus, errorThrown){
                var bbb="";
              },
              success:function (data, textStatus, jqXHR){
                //that.SetContact();
              }
            });
//            document.write("<script src='"+taobaoFilePath+"'></"+"script>");
            //$.getScript(qqFilePath);
            if(!this.isFinded){
                this.SetContactByAddressAndType(this.contactWays[0].Address,this.contactWays[0].Type);
            }

            
        },
        SetContact:function(taobaoResponse){
            if(this.isFinded){
                return;
            }
            for(var i=0;i<online.length;i++){
                /*online*/
                if(online[i]==1){
                    var address=this.GetDataByQQ(i);
                    this.SetContactByAddressAndType(address,1);
                    this.isFinded=true;
                    return;
                }
            }
            if(taobaoResponse==undefined){
                return;
            }
            for(var i=0;i<taobaoResponse.data.length;i++){
                if(taobaoResponse.data[i]==1){
                    var address=this.GetDataByTaoBao(i);
                    this.SetContactByAddressAndType(address,0);
                    this.isFinded=true;
                    return;
                }
            }
        },
        GetDataByQQ:function(index){
            var result;
            var i=0;
            $.each(this.contactWays,function(idex,item){
                /*1代表是QQ*/
                if(item.Type==1){
                    if(i==index){
                        result= item.Address;
                        return;
                    }
                    i++;
                }
                
            });
            return result;
        },
        GetDataByTaoBao:function(index){
            var result;
            var i=0;
            $.each(this.contactWays,function(idex,item){
                /*0代表是淘宝*/
                if(item.Type==0){
                    if(i==index){
                        result= item.Address;
                        return;
                    }
                    i++;
                }
                
            });
            return result;
        },
        SetContactByAddressAndType:function(address,type){
            if(type==1){
                var qqhref="http://"+"wpa.qq.com/msgrd?v=3&amp;uin="+encodeURI(address)+"&amp;site=qq&amp;menu=yes";
                var qqsrc="http://"+"wpa.qq.com/pa?p=2:"+encodeURI(address)+":41";
                $("#contactLink").attr("href",qqhref);
                $("#contactImg").attr("src",qqsrc);
            }else if(type==0){
                var taobaohref="http://"+"www.taobao.com/webww/ww.php?ver=3&touid="+encodeURI(address)+"&siteid=cntaobao&status=1&charset=utf-8";
                var taobaosrc="http://"+"amos.alicdn.com/realonline.aw?v=2&uid="+encodeURI(address)+"&site=cntaobao&s=1&charset=utf-8";
                $("#contactLink").attr("href",taobaohref);
                $("#contactImg").attr("src",taobaosrc);
            }
        }
    }

        var MyHome;
        $().ready(function () {
            MyHome = $("#MyHome").validate();
        });

        var Students = {
            CreateStudent: function () {
                var student = $("#student");
                var currentStudent = student.clone();
                student.parent().append(currentStudent);
            },
            DeleteStudent: function (obj) {
                var student = $(obj).parent().parent();
                if (student.parent().find(".student").find("div").length == 1) {
                    DialogMessage.Show(2, "下单必须保留一个学员");
                }
                DialogMessage.ConfirmShow("提示", "确定要该学员？", function () {
                    student.remove();
                });
            }, /*学生表单验证*/
            ValidateInfo: function () {

                var student = $("#student");
                var students = student.parent().find("div");
                var result = true;
                students.each(function (index, item) {
                    var txt_name = $(item).find("input[type=text]").eq(0);
                    var txt_age = $(item).find("input[type=text]").eq(1);
                    var name = txt_name.val();
                    var age = txt_age.val();
                    var lb_name=txt_name.next("label").eq(0);
                    var lb_age=txt_age.next("label").eq(0);
                    
                    if (age==""||isNaN(age) || parseInt(age) == 0 || parseInt(age) > 18) {
                        lb_age.html("年龄请输入1到18岁范围内");
                        lb_age.show();
                        txt_age.focus();
                        result = false;
                    } else {
                        lb_age.html("");
                    }
                    
                    if (name.length > 20 || name.length == 0) {
                        
                        lb_name.html("姓名请输入0到20 字符");
                        lb_name.show();
                        txt_name.focus();
                        result = false;
                    } else {
                        lb_name.html("");
                    }

                   
                });

                if(result==false){
                    return result;
                }

                  /*验证库存*/
                $.ajax({
                            type: "post",
                            dataType: "text",
                            //data: { OrderNumber: ordernumber, ShipmentID:shipmentID, Notes: notes, Action: "CancelShipmentByID" },
                            url: "CreateOrder.aspx?surplusenjoycount_id=" + <%=Request["id"] %>,
                            async: false,
                            error: function (result) {
                                result;
                            },
                            success: function (data, textStatus) {
                                
                                //执行成功
                                if (parseInt(data)< students.length) {
                                    DialogMessage.Show(2, "您请求的课程信息剩余量为"+data+",而当前填写的学生信息为"+students.length+"条,请您调整学生信息或联系服务提供者", function () {
                                        
                                    });
                                    result=false;
                                }
                            }
                        });
                return result;
            }, /*生成student的结果值*/
            GenerateValue: function () {
                var student = $("#student");
                var students = student.parent().find("div");
                var txt_student=$("#<%=Txt_Students.ClientID %>");
                students.each(function (index, item) {
                    var name = $(item).find("input[type=text]").eq(0).val();
                    var age = $(item).find("input[type=text]").eq(1).val();
                    var result;
                    if (index == 0) {
                        result = name + "|" + age;
                    }
                    else {
                        result = "," + name + "|" + age;
                    }
                    txt_student.val(txt_student.val()+result);
                });
            }
        };
   function SubmitOrder() { 
       
        /*表单验证*/ 
        if (!$("#MyHome").valid()) { return false; } 
       
        /*学生表单验证*/
        if (!Students.ValidateInfo()) { return false; }

      

       /*生成student的结果值*/ 
        Students.GenerateValue();
        return true; 
    }
  
    </script>
</asp:Content>
<asp:Content ID="CSPCrumbs" ContentPlaceHolderID="CSPCrumbs" runat="server">
</asp:Content>
<asp:Content ID="CSPMain" ContentPlaceHolderID="CSPMain" runat="server">
    <div class="box-bd post-message home">
        <!-- {{{ flowsteps -->
        <div class="flowsteps">
            <ol class="num2">
                <li class="current"><span class="first">1. 填写预约信息</span></li>
                <li class="next"><span class="last">2. 预约成功</span></li>
            </ol>
        </div>
        <!-- flowsteps }}} -->
        <div class="post-cont mh500">
            <div class="book-info">
                <div class="course">
                    <div class="sum-wrap">
                        <div class="summary">
                            <h3 class="course-title">
                                <a href="/detail/<%=Request["id"].ToString() %>.shtml">
                                    <asp:Label ID="LB_Title" runat="server" Text="Label"></asp:Label></a></h3>
                            <p class="old-price">
                                <del>原价：<strong><asp:Label ID="LB_OriginalPrice" runat="server" Text="Label"></asp:Label></strong>元/<asp:Label
                                    ID="LB_OriginalPriceUnit" runat="server" Text="Label"></asp:Label></del></p>
                            <p class="latest-price">
                                现价：<span class="price"><asp:Label ID="LB_Price" runat="server" Text="Label"></asp:Label></span>元/<asp:Label
                                    ID="LB_PriceUnit" runat="server" Text="Label"></asp:Label>
                            </p>
                            <p class="class-number">
                                开班人数：<asp:Label ID="LB_ClassOfMemberNumber" runat="server" Text="Label"></asp:Label>人</p>
                        </div>
                    </div>
                    <div class="photo-contact">
                        <div class="photo">
                            <a href="">
                                <img src="/images/org-photo.png" width="100" height="74" alt=""></a></div>
                    </div>
                </div>
                <div class="enterprise">
                    <div class="sever-name">
                        <p>
                            服务机构：<a href="/detail/<%=Request["id"].ToString() %>.shtml" class="name"><asp:Label
                                ID="LB_UserName" runat="server" Text="Label"></asp:Label></a> <a title="<%=AthenticationName %>"
                                    class="ico <%=AuthenticationStyle %>" href=""></a>
                        </p>
                        <p>
                            咨询电话：010-25142548</p>
                        <p>
                            客服在线：<%--<a id="contactLink" href=""
                                target="_blank"><img border="0" id="contactImg" align="absmiddle" title="点击这里给我发消息"
                                    alt="点击这里给我发消息" src=""></a>--%></p>
                        <p class="sever-local">
                            服务区域：<a><asp:Label ID="LB_Province" runat="server" Text=""></asp:Label></a> <a>
                                <asp:Label ID="LB_City" runat="server" Text=""></asp:Label></a> <a>
                                    <asp:Label ID="LB_County" runat="server" Text=""></asp:Label></a>
                            <asp:Label ID="LB_Street" runat="server" Text=""></asp:Label>
                            <a href="" title="点击查看详细" class="ico i-local">查看详细</a></p>
                    </div>
                </div>
            </div>
            <!--book-info-->
            <div class="book-steps">
                <ul>
                    <li class="">
                        <div class="steps-hd">
                            <h3>
                                预约人信息</h3>
                            <div class="hd-extra">
                                请准确填写预约联系人信息，预约的任何信息我们将通知联系人</div>
                        </div>
                        <div class="steps-bd">
                            <ul class="fill_in_content">
                                <li>
                                    <p class="title">
                                        <span class="fc-red">*</span>联系人姓名：</p>
                                    <p class="fill_in">
                                        <input id="Txt_ContactedMan" class="text3 {required:true,maxlength:20}" type="text"
                                            runat="server" name="linkman">
                                    </p>
                                </li>
                                <li>
                                    <p class="title">
                                        地址：</p>
                                    <p class="fill_in">
                                        <textarea id="Txt_Adress" class="text3 {maxlength:100}" rows="5" cols="40" runat="server"></textarea>
                                    </p>
                                </li>
                                <li>
                                    <p class="title">
                                        <span class="fc-red">*</span>手机号码：</p>
                                    <p class="fill_in">
                                        <input id="Txt_Phone" class="text3  {required:true,number:true,messages:{required:'请填写手机号码',number:'请填写正确的手机格式'}}"
                                            runat="server" type="text" name="phone_mob">
                                        <span class="field_message explain"><span class="field_notice">（用于接收短信）</span></span>
                                    </p>
                                </li>
                                <li>
                                    <p class="title">
                                        邮 &nbsp;&nbsp;&nbsp; 箱：</p>
                                    <p class="fill_in">
                                        <input type="text" class="text3 {required:true,email:true,messages:{required:'请填写邮箱',email:'请填写正确的邮箱格式'}}"
                                            runat="server" name="email" id="Txt_Email">
                                    </p>
                                </li>
                            </ul>
                        </div>
                    </li>
                    <li>
                        <div class="steps-hd">
                            <h3>
                                学员信息</h3>
                        </div>
                        <div class="steps-bd">
                            <div id="studentlist">
                                <div>
                                    <div style="" class="student" id="student">
                                        <h4>
                                            <strong>预约学员</strong><a style="cursor:pointer" onclick="javascript:Students.DeleteStudent(this);"><i class="ico i-del"></i>删除该学员</a>
                                        </h4>
                                        <ul class="fill_in_content ">
                                            <li>
                                                <p class="title">
                                                    <span class="fc-red">*</span>学员姓名：</p>
                                                <p class="fill_in">
                                                    <input type="text" class="text3 " rule="{required:true,messages:{required:'请填写学员的姓名'}}"
                                                        ename="child_name" name="child[0][child_name]">
                                                </p>
                                            </li>
                                            <li>
                                                <p class="title">
                                                    <span class="fc-red">*</span>学员年龄：</p>
                                                <p class="fill_in">
                                                    <input type="text" class="text3" rule="{required:true,number:true,range:[0,18],messages:{required:'请填写学员的年龄',number:'学员年龄只可以为数字',range:'年龄只能为0-18的数字'}}"
                                                        ename="age" name="child[0][age]">
                                                    <span class="field_message explain"><span class="field_notice">（年龄小于12个月的请输入1岁）</span></span>
                                                </p>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="option">
                                    <a href="javascript:Students.CreateStudent();" class="post-btn-a"><span>新增学员</span></a>
                                    <input id="Txt_Students" type="text" runat="server" style="display: none">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="steps-hd">
                            <h3>
                                支付方式</h3>
                        </div>
                        <div class="steps-bd">
                            <div class="pay-way">
                                <img src="/images/pay-way.png" align="absmiddle" width="125" height="47" alt="到店支付">
                                免费预约用户免费在线预约，到商家消费。</div>
                        </div>
                    </li>
                    <li>
                        <div class="steps-hd">
                            <h3>
                                预约信息</h3>
                        </div>
                        <div class="steps-bd">
                            <ul id="address_form" class="fill_in_content">
                                <li>
                                    <p class="title">
                                        <span class="fc-red">*</span>预约时间：</p>
                                    <p class="fill_in">
                                        <CSP_U:CSPDatePicker runat="server" ID="Txt_AppointmentDate" Class="text3 {required:true,date:true,messages:{required:'请选择你可能到商家的时间',date:'请填写正确的日期格式'}}" />
                                        <span class="field_message explain"><span class="field_notice">请选择你可能到商家的时间</span></span>
                                    </p>
                                </li>
                                <li>
                                    <p class="title">
                                        补充说明：</p>
                                    <p class="fill_in">
                                        <textarea id="Remark" runat="server" name="message" rows="4" cols="40" class="text3 {maxlength:150}"></textarea>
                                        <span class="field_message explain"><span class="field_notice">选填,可以告诉商家你对预约的特殊需求。</span></span>
                                    </p>
                                </li>
                            </ul>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="book-submit">
                <input class="ui-btn-confirm" onclick="return SubmitOrder()" type="submit" onserverclick="Btn_Submit_Click"
                    runat="server" value="确定预约"></div>
        </div>
        <!--post-cont-->
    </div>
</asp:Content>
